home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_time.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.3 KB  |  51 lines

  1. import test_support
  2. import time
  3. import unittest
  4.  
  5.  
  6. class TimeTestCase(unittest.TestCase):
  7.  
  8.     def setUp(self):
  9.         self.t = time.time()
  10.  
  11.     def test_data_attributes(self):
  12.         time.altzone
  13.         time.daylight
  14.         time.timezone
  15.         time.tzname
  16.  
  17.     def test_clock(self):
  18.         time.clock()
  19.  
  20.     def test_conversions(self):
  21.         self.assert_(time.ctime(self.t)
  22.                      == time.asctime(time.localtime(self.t)))
  23.         self.assert_(long(time.mktime(time.localtime(self.t)))
  24.                      == long(self.t))
  25.  
  26.     def test_sleep(self):
  27.         time.sleep(1.2)
  28.  
  29.     def test_strftime(self):
  30.         tt = time.gmtime(self.t)
  31.         for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
  32.                           'j', 'm', 'M', 'p', 'S',
  33.                           'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
  34.             format = ' %' + directive
  35.             try:
  36.                 time.strftime(format, tt)
  37.             except ValueError:
  38.                 self.fail('conversion specifier: %r failed.' % format)
  39.  
  40.     def test_asctime(self):
  41.         time.asctime(time.gmtime(self.t))
  42.         self.assertRaises(TypeError, time.asctime, 0)
  43.  
  44.  
  45. def test_main():
  46.     test_support.run_unittest(TimeTestCase)
  47.  
  48.  
  49. if __name__ == "__main__":
  50.     test_main()
  51.